<?php

namespace App\Console\Commands;

use App\Library\Import\ImportProduct;
use App\Library\Logic\ImportPlugLogic;
use App\Library\Logic\ImportProductLogic;
use Illuminate\Console\Command;
use Maatwebsite\Excel\Facades\Excel;

class ImportPlugCommand extends Command
{
    /**
     * 导入捡漏商品
     *
     * @var string
     */
    protected $signature = 'command:importPlug {serialNumber}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle(): void
    {
        $serialNumber = $this->argument('serialNumber');
        if (empty($serialNumber) || strlen($serialNumber) !== 20) return;
        $item = ImportPlugLogic::findBySerialNumber($serialNumber);
        if (is_null($item) || $item->status !== 0) return;
        $file = public_path('upload/' . $item->file);
        if (!is_file($file)) {
            $item->status = 2;
            $item->error = ['文件不存在'];
            $item->save();
        }
        //Excel::import(new ImportProduct($item), $file);
    }
}
